{% extends 'base.html' %}

{% block title %}环境数据列表{% endblock %}

{% block content %}
<div class="card">
    <div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
        <h4 class="mb-0">环境数据管理</h4>
        <a href="{{ url_for('data.environment_add') }}" class="btn btn-light">添加环境数据</a>
    </div>
    <div class="card-body">
        <!-- 搜索表单 -->
        <form method="get" class="mb-4">
            <div class="row g-3">
                <div class="col-md-3">
                    <input type="text" class="form-control" name="search_region" value="{{ search_region }}" placeholder="搜索区域...">
                </div>
                <div class="col-md-2">
                    <input type="date" class="form-control" name="date_from" value="{{ date_from }}" placeholder="开始日期">
                </div>
                <div class="col-md-2">
                    <input type="date" class="form-control" name="date_to" value="{{ date_to }}" placeholder="结束日期">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">搜索</button>
                </div>
                <div class="col-md-2">
                    <a href="{{ url_for('data.environment_list') }}" class="btn btn-secondary w-100">重置</a>
                </div>
            </div>
        </form>

        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>区域</th>
                        <th>日期</th>
                        <th>温度(℃)</th>
                        <th>降雨量(mm)</th>
                        <th>土壤类型</th>
                        <th>土壤肥力</th>
                        <th>光照强度(lux)</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in pagination.items %}
                    <tr>
                        <td>{{ item.region }}</td>
                        <td>{{ item.date.strftime('%Y-%m-%d') }}</td>
                        <td>{{ item.temperature }}</td>
                        <td>{{ item.rainfall }}</td>
                        <td>{{ item.soil_type }}</td>
                        <td>{{ item.soil_fertility }}</td>
                        <td>{{ item.light_intensity }}</td>
                        <td>
                            <div class="btn-group btn-group-sm">
                                <a href="{{ url_for('data.environment_edit', id=item.id) }}" class="btn btn-primary">编辑</a>
                                <form action="{{ url_for('data.environment_delete', id=item.id) }}" method="post" class="d-inline" onsubmit="return confirm('确定要删除这条记录吗？');">
                                    <button type="submit" class="btn btn-danger">删除</button>
                                </form>
                            </div>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        
        {% include 'includes/pagination.html' %}
    </div>
</div>
{% endblock %} 